package com.wang.madness.config;

import com.wang.madness.interceptor.JwtAuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 王文君
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

  private final JwtAuthenticationInterceptor jwtAuthenticationInterceptor;

  /**
   * 通过有参构造器注入自定义拦截器
   *
   * @param jwtAuthenticationInterceptor jwt拦截器
   */
  @Autowired
  public InterceptorConfig(JwtAuthenticationInterceptor jwtAuthenticationInterceptor) {
    this.jwtAuthenticationInterceptor = jwtAuthenticationInterceptor;
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    // 默认拦截所有路径
    registry.addInterceptor(jwtAuthenticationInterceptor).addPathPatterns("/api/**");
  }
}
